define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function(){
		this.streetId = '';
		this.loadDone = false;
		this.callParent();
	};


	Model.prototype.modelParamsReceive = function(event){	    
		this.streetId = event.params.streetId;
		this.comp("areaList").refresh(true);
	};

	Model.prototype.areaListClick = function(event){
		var areaId = this.comp("areaData").getCurrentRowID();
		justep.Shell.showPage("$UI/communityOto/community/communityList.w",{"areaId":areaId});

	};

	Model.prototype.areaDataCustomRefresh = function(event){
	    
		if(this.streetId){
			if(event.source.count() < event.offset){
				return;
			}
			
			this.comp("popOver1").show();
			var me = this;
			var url = this.getParentModel().serverUrl + "/ex_community/a/api/community/findOfficeByAreaId?callback=?";
			var page = event.offset/event.limit + 1;
			$.getJSON(url,{"area.id":this.streetId,"pageNo":page,"pageSize":event.limit},function(data){
			    if(data && data.data){
			       
			    	event.source.loadData(data.data,true,null,event.offset,true);
			    	me.loadDone = true;
			    	me.comp("popOver1").hide();
			    }
				
			});
			
		}

	};

	Model.prototype.scrollView1PullDown = function(event){
		this.comp("areaData").refreshData();
	};

	Model.prototype.scrollView1PullUp = function(event){
		if(this.loadDone){
			this.loadDone = false;
			this.comp("areaData").loadNextPageData();
		}
		

	};

	Model.prototype.areaDataBeforeRefresh = function(event){
		this.loadDone = false;

	};

	return Model;
});